import UIKit
import Flutter
import Bugly

@main
@objc class AppDelegate: FlutterAppDelegate {
    
    override func application(
      _ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        
        configBugly()
        BTApplePay.share()
        GeneratedPluginRegistrant.register(with: self)
        let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
        AppFlutterBridge.shared.setBridge(controller: controller)
        
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    
    func configBugly() -> Void{
        let buglyConfig = BuglyConfig()
        buglyConfig.deviceIdentifier = BTDeviceTool.identify()
        buglyConfig.channel = "default"
        buglyConfig.version = String.init(format: "%@(%@)", BTUtils.appVersion(),BTUtils.appBuildVersion(),)
        
        if BTEnvDefine.isDebug(){
            BTLogMananger.save("这是 Debug 模式")
            Bugly.start(withAppId: "a76ce5866a", config: buglyConfig)
        }else{
            BTLogMananger.save("这是 Release 模式")
            Bugly.start(withAppId: "6febe4b95a", config: buglyConfig)
        }
    }
    
}
